package com.dlu.safe_construction.common.utils;

import com.alibaba.fastjson.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.List;
import java.util.Map;

/**
 * Created by 李家兴
 * Date 2020/1/31
 * Description
 */
public class Utils {

    final static Base64.Encoder encoder = Base64.getEncoder();
    final static Base64.Decoder decoder = Base64.getDecoder();

    public static boolean isEmpty(Object o) {
        if (o == null) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNotEmpty(Object o) {
        if (o == null) {
            return false;
        } else {
            return true;
        }
    }

    public static boolean isNotEmpty(List<Object> list) {
        if (list == null || list.size() == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static String generateId() {
        return String.valueOf((int) ((Math.random() * 9 + 1) * 10000000));
    }

    public static String decode(String str) {
        String encodeStr = null;
        try {
            encodeStr = new String(decoder.decode(str), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encodeStr;
    }

    public static Map<String, Object> fromJson(String json) {
        Map<String, Object> resultMap = JSONObject.parseObject(json);
        return resultMap;
    }
}
